<template>
  <view class="result_wrapper">
    <!-- 结果卡片 -->
    <view class="result_card">
      <view class="result_header">
        <text class="result_title">答题结果</text>
      </view>
      
      <view class="result_content">
        <!-- 正确率 -->
        <view class="result_item">
          <text class="result_label">正确率</text>
          <text class="result_value">{{ accuracy }}%</text>
        </view>
        
        <!-- 答题数 -->
        <view class="result_item">
          <text class="result_label">答题正确数</text>
          <text class="result_value">{{ correctCount }}/{{ totalCount }}</text>
        </view>
        
        <!-- 学习时长 -->
        <view class="result_item">
          <text class="result_label">学习时长</text>
          <text class="result_value">{{ studyTimeInMinutes }}分钟</text>
        </view>
        
        <!-- 状态 -->
        <view class="result_item">
          <text class="result_label">状态</text>
          <text class="result_value">{{ status }}</text>
        </view>
      </view>
      
      <!-- 返回按钮 -->
      <view class="result_footer">
        <button class="submit_button" @tap="handleBack">返回</button>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      accuracy: 0,
      correctCount: 0,
      totalCount: 0,
      studyTimeInMinutes: 0,
      status: ''
    };
  },
  onLoad(options) {
    if (options.result) {
      const result = JSON.parse(options.result);
      console.log('答题结果数据:', result); // 添加日志调试
      this.accuracy = Math.min((result.accuracy * 1).toFixed(1), 100);
      this.correctCount = result.correctCount;
      this.totalCount = result.totalCount;
      this.studyTimeInMinutes = this.formatTime(result.studyTimeInMinutes);
      this.status = result.status;
    }
  },
  methods: {
    formatTime(seconds) {
      const mins = Math.floor(seconds / 60);
      const secs = Math.round(seconds % 60);
      return `${mins}分钟${secs}秒`;
    },
    handleBack() {
      uni.redirectTo({
        url: '/pages/category/index'
      });
    }
  }
};
</script>

<style>
.result_wrapper {
  background: linear-gradient(135deg, rgba(170, 207, 252, 1) 0%, rgba(187, 208, 251, 1) 50%, rgba(178, 236, 248, 1) 100%);
  min-height: 100vh;
  padding: 30rpx;
  display: flex;
  justify-content: center;
  align-items: center;
}

.result_card {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 20rpx;
  width: 90%;
  padding: 40rpx;
  box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.1);
}

.result_header {
  margin-bottom: 40rpx;
}

.result_title {
  font-size: 40rpx;
  font-weight: bold;
  color: #1d2342;
  text-align: center;
}

.result_content {
  margin-bottom: 40rpx;
}

.result_item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20rpx 0;
  border-bottom: 1rpx solid #f0f0f0;
}

.result_label {
  font-size: 32rpx;
  color: #1d2342b0;
}

.result_value {
  font-size: 32rpx;
  font-weight: bold;
  color: #5983ff;
}

.result_footer {
  margin-top: 40rpx;
}

.submit_button {
  background: #5983ff;
  color: white;
  border-radius: 40rpx;
  font-size: 28rpx;
  padding: 20rpx 0;
}
</style>